#!/usr/bin/env python
#-*- coding:utf-8 -*-

#file: L0Q3.py

import sys

def calc(matrix):
    colunas_m = len(matrix[0])
    linhas_m = len(matrix)

    result = []

    for i in range(linhas_m):
        line =[]
        for j in range(colunas_m):
            value = 0
            for row in matrix[:i+1]:
                for item in row[:j+1]:
                    value += item

            value = value / ((i + 1) * (j + 1))

            line.append(value)

        result.append(line)

    return result


def read_input(filename="L0Q3.in"):
    f = open(filename, "r")
    lines = f.readlines()
    f.close()

    matrices = []
    i = 0
    lines_num = len(lines)
    while i < lines_num:
        rows, columns = [int(n) for n in lines[i].split(' ')]

        m1 = []
        for l in range(rows):
            i += 1
            m1.append([int(n) for n in lines[i].split(' ')])

        i += 1
        if i < lines_num and lines[i].strip() == '':
            i += 1

        matrices.append(m1)

    return matrices


def write_output(matrix):
    try:
        for row in matrix:
            for item in row:
                print item,
            print
    except TypeError, e:
        print matrix

    print


def main():
    if len(sys.argv) > 1:
        input_file = sys.argv[1]
    else:
        input_file = sys.argv[0]
        start = input_file.rfind('/') + 1
        end = input_file.rfind('.py')
        input_file = input_file[start:end] + '.in'

    try:
        input = read_input(input_file)
    except IOError, e:
        print 'Arquivo de entrada "%s" nao encontrado.' % \
                input_file
        sys.exit(1)

    i = 0
    for matrix in input:
        i += 1
        m = calc(matrix)

        print 'Conjunto #%d' % i
        write_output(m)


if __name__ == '__main__':
    main()

